package com.atguigu.cmsservice.controller;


import com.atguigu.cmsservice.entity.CrmBanner;
import com.atguigu.cmsservice.service.CrmBannerService;
import com.atguigu.commonutils.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author xuan
 * @since 2020-04-19
 */
@Api(description="轮播图管理")
@CrossOrigin
@RestController
@RequestMapping("educms")
public class CrmBannerController {

    @Autowired
    CrmBannerService bannerService;

    @GetMapping("getBannerList")
    public R getBannerList(){
        List<CrmBanner> bannerList = bannerService.getBannerList();
        return R.ok().data("bannerList",bannerList);
    }

    @GetMapping("getHotTeachers")
    public R getHotTeachers(){
        QueryWrapper<CrmBanner> bannerWrapper = new QueryWrapper<>();
        bannerWrapper.orderByAsc("id").last("limit 3");
        List<CrmBanner> bannerList = bannerService.list(bannerWrapper);
        return R.ok().data("bannerList",bannerList);
    }

    @GetMapping("getHotCourses")
    public R getHotCourses(){
        QueryWrapper<CrmBanner> bannerWrapper = new QueryWrapper<>();
        bannerWrapper.orderByAsc("id").last("limit 3");
        List<CrmBanner> bannerList = bannerService.list(bannerWrapper);
        return R.ok().data("bannerList",bannerList);
    }


}

